const initialState = {
  value: 0,
  loading: false,
  error: null,
};

export default function counterReducer(state = initialState, action) {
  switch (action.type) {
    case "counter/fetchStart":
      return { ...state, loading: true, error: null };
    case "counter/fetchSuccess":
      return { ...state, loading: false, value: state.value + action.payload };
    case "counter/fetchError":
      return { ...state, loading: false, error: action.error };
    case "counter/syncAdd":
      return { ...state, value: state.value + action.payload };
    default:
      return state;
  }
}
